package cn.woflcode.game.model;

import cn.woflcode.game.Global.Global;
import cn.woflcode.game.Global.ImageUtil;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom;

public class Life {
    //位置:x坐标
    private int x;
    //位置:y坐标
    private int y;
    //大小:宽
    private int width;
    //大小:高
    private int height;
    private int spead=1;
    //图片
    private BufferedImage image = ImageUtil.getImage("life");
    //-------------构造器---------------------
    public Life(){
        this.width = image.getWidth();  //获取图片的宽度
        this.height = image.getHeight();//获取图片的高度
        this.x= ThreadLocalRandom.current().nextInt(0, Global.GAME_UI_WIDTH-width);

        this.y=-height;
    }
    //--------------功能---------------
    //画自己
    public void drawSelf(Graphics g){
        g.drawImage(image,x,150,null);
    }
    //移动
    public void move(){
        this.y+=spead;
    }
    public int getCenterX(){
        return x+width/2;
    }
    //圆y坐标
    public int getCenterY(){
        return y+height/2;
    }
    //圆半径
    public int getR(){
        return Math.min(width,height)/2;
    }
}
